import 'ly_works_comment_model.dart';

class LyUserModel {
  LyUserModel(
      {this.userId,
      this.nickname,
      this.avatar,
      this.worksNum,
      this.works,
      this.followNum});

  LyUserModel.fromJson(dynamic json) {
    userId = json['userId'];
    nickname = json['nickname'];
    avatar = json['avatar'];
    followNum = json['followNum'];
    worksNum = json['worksNum'];
    isFriend = json['isFriend'];
    age = json['age'];
    country = json['country'];
    if (json['works'] != null) {
      works = [];
      json['works'].forEach((v) {
        works?.add(LYWorksModel.fromJson(v));
      });
    }
  }
  String? userId;
  String? nickname;
  String? avatar;
  num? worksNum;
  num? followNum;
  List<LYWorksModel>? works;
  bool? isFriend;
  num? age;
  String? country;
  LyUserModel copyWith({
    String? userId,
    String? nickname,
    String? avatar,
    num? worksNum,
    List<LYWorksModel>? works,
  }) =>
      LyUserModel(
        userId: userId ?? this.userId,
        nickname: nickname ?? this.nickname,
        avatar: avatar ?? this.avatar,
        worksNum: worksNum ?? this.worksNum,
        works: works ?? this.works,
      );
  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['userId'] = userId;
    map['nickname'] = nickname;
    map['avatar'] = avatar;
    map['worksNum'] = worksNum;
    map['followNum'] = followNum;
    map['isFriend'] = isFriend;
    map['age'] = age;
    map['country'] = country;
    if (works != null) {
      map['works'] = works?.map((v) => v.toJson()).toList();
    }
    return map;
  }
}

class LYWorksModel {
  LYWorksModel(
      {this.title,
      this.description,
      this.cover,
      this.images,
      this.comments,
      this.userId});

  LYWorksModel.fromJson(dynamic json) {
    title = json['title'];
    description = json['description'];
    userId = json['userId'];
    nickname = json['nickname'];
    avatar = json['avatar'];
    cover = json['cover'];
    upvote = json['upvote'];
    isGreat = json['isGreat'];
    id = json['id'];
    isSave = json['isSave'];
    isBlack = json['isBlack'];
    images = json['images'] != null ? json['images'].cast<String>() : [];
    if (json['comments'] != null) {
      comments = [];
      json['comments'].forEach((v) {
        comments?.add(LYWorksCommentModel.fromJson(v));
      });
    }
  }
  String? title;
  String? description;
  String? cover;
  String? userId;
  String? nickname;
  String? avatar;
  List<String>? images;
  num? upvote;
  bool? isGreat;
  String? id;
  bool? isSave;
  bool? isBlack;
  String? translateContent;
  List<LYWorksCommentModel>? comments;
  LYWorksModel copyWith({
    String? title,
    String? description,
    String? cover,
    List<String>? images,
  }) =>
      LYWorksModel(
        title: title ?? this.title,
        description: description ?? this.description,
        cover: cover ?? this.cover,
        images: images ?? this.images,
      );
  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['title'] = title;
    map['description'] = description;
    map['cover'] = cover;
    map['images'] = images;
    map['userId'] = userId;
    map['nickname'] = nickname;
    map['avatar'] = avatar;
    map['upvote'] = upvote;
    map['isGreat'] = isGreat;
    map['id'] = id;
    map['isSave'] = isSave;
    map['isBlack'] = isBlack;
    if (comments != null) {
      map['comments'] = comments?.map((v) => v.toJson()).toList();
    }
    return map;
  }
}
